﻿using System;
using System.Windows.Forms;
using Storm.TextEditor.Languages;
using Moonlite.ExtensionApi.ControlInterfaces;
using Moonlite.ExtensionApi.GlobalInterfaces;
using Moonlite.Platform.General;
using Moonlite.Platform.Project;

namespace Moonlite.UI.Shell.Controls {
    public partial class CodeExplorer : UserControl, ICodeExplorer {
        public void SetCode(string code) {
            if (textEditor.Text != code && Visible)
            {
                Clear();
                textEditor.Text = code;
                textEditor.Document.Folding = false;
                if (Global.Instance.Project.Type == ProjectType.Galaxy)
                {
                    if (textEditor.CurrentLanguage != XmlLanguage.Andromeda)
                    {
                        textEditor.CurrentLanguage = XmlLanguage.Andromeda;
                    }
                }
                else
                {
                    if (textEditor.CurrentLanguage != XmlLanguage.vJass)
                    {
                        textEditor.CurrentLanguage = XmlLanguage.vJass;
                    }
                }
            }
        }

        public void Clear() {
            textEditor.Text = "";
        }

        public CodeExplorer() {
            InitializeComponent();
            try { Global.Instance.RegisterService(this, GetType().GetInterface("ICodeExplorer")); }
            catch { }
        }
    }
}
